﻿package mortal.game.view.skill
{
    import Message.Client.*;
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import extend.language.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.rules.*;
    import mortal.game.scene3D.ai.data.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.view.palyer.util.*;

    public class SkillUtil extends Object
    {
        private static var comboDic:Dictionary = new Dictionary();

        public function SkillUtil()
        {
            return;
        }// end function

        public static function isGuildSkill(param1:TSkill) : Boolean
        {
            if (param1 == null)
            {
                return false;
            }
            if (param1.type != ESkillType._ESkillTypeUnion)
            {
                return false;
            }
            return true;
        }// end function

        public static function getCarrer(param1:TSkill) : int
        {
            switch(param1.career)
            {
                case 1:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            return 0;
        }// end function

        public static function isNextSkillByTskill(param1:TSkill, param2:TSkill) : Boolean
        {
            if (param1.series != param2.series)
            {
                return false;
            }
            if (param1.skillLevel == (param2.skillLevel + 1))
            {
                return true;
            }
            return false;
        }// end function

        public static function getNeedCoolDownSkills() : Array
        {
            var _loc_3:TSkill = null;
            var _loc_1:Array = [];
            var _loc_2:* = SkillConfig.instance.getSkillsDic();
            for each (_loc_3 in _loc_2)
            {
                
                if (_loc_3.career > 0)
                {
                    if (_loc_3.posType > 0)
                    {
                        if (_loc_3.cooldownTime > 0)
                        {
                            _loc_1.push(_loc_3);
                        }
                    }
                }
            }
            return _loc_1;
        }// end function

        public static function alyRuneDesc(param1:TRune) : String
        {
            var _loc_2:int = 0;
            if (param1.description)
            {
                _loc_2 = int(param1.description);
                if (_loc_2 > 0)
                {
                    param1.description = DescConfig.instance.getDescAlyzObj(_loc_2, param1);
                }
            }
            return param1.description;
        }// end function

        public static function alySkillDesc(param1:TSkill) : String
        {
            var _loc_2:int = 0;
            if (param1.skillDescription)
            {
                _loc_2 = int(param1.skillDescription);
                if (_loc_2 > 0)
                {
                    param1.skillDescription = DescConfig.instance.getDescAlyzObj(_loc_2, param1);
                }
            }
            return param1.skillDescription;
        }// end function

        public static function getSkillDesc(param1:int) : String
        {
            var _loc_2:* = SkillConfig.instance.getInfoById(param1);
            if (_loc_2 == null)
            {
                return "";
            }
            var _loc_3:* = parseInt(SkillUtil.alySkillDesc(_loc_2));
            if (_loc_3 >= 10000000 && _loc_3 <= 99999999)
            {
                return "等策划把描述配置表";
            }
            return _loc_2.skillDescription;
        }// end function

        public static function getSkillUseTypeName(param1:TSkill) : String
        {
            if (param1.triggerType == ESkillTriggType._ESkillTriggBeAttack || param1.triggerType == ESkillTriggType._ESkillTriggBorn)
            {
                return Language.getString(20235);
            }
            if (param1.rangeType == ESkillRangeType._ESkillRangeTypeSingle)
            {
                return Language.getString(20233);
            }
            return Language.getString(20234);
        }// end function

        public static function isBeidongSkill(param1:int) : Boolean
        {
            var _loc_2:* = SkillConfig.instance.getInfoById(param1);
            if (_loc_2.triggerType != ESkillTriggType._ESkillTriggActive && _loc_2.triggerType != ESkillTriggType._ESkillTriggSummon)
            {
                return true;
            }
            return false;
        }// end function

        public static function getBassicAttackPercentage(param1:TSkill) : int
        {
            var _loc_2:* = param1.hurtEffect.toString();
            return parseInt(_loc_2.substr(_loc_2.length - 3));
        }// end function

        public static function getAttachAttackValue(param1:TSkill) : int
        {
            var _loc_2:* = param1.hurtEffect.toString();
            return parseInt(_loc_2.substr(0, _loc_2.length - 3));
        }// end function

        public static function isAutoFightSkill(param1:SkillInfo) : Boolean
        {
            var _loc_2:* = param1.tSkill.targetType;
            if (!(_loc_2 & ESkillTargetType._ESkillTargetTypeEnemy))
            {
                return false;
            }
            return true;
        }// end function

        public static function getSkillName(param1:SkillInfo, param2:String = "{0}") : String
        {
            var _loc_3:String = "";
            if (param1)
            {
                _loc_3 = HTMLUtil.addColor(param2.replace("{0}", param1.skillName), ColorConfig.instance.getItemColor(param1.skillLevel).color);
            }
            return _loc_3;
        }// end function

        public static function isRuneBelongsToSkill(param1:TRune, param2:TSkill) : Boolean
        {
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            var _loc_5:TSkill = null;
            if (param2 == null || param1 == null)
            {
                return false;
            }
            if (param1.skillBelong == param2.series)
            {
                return true;
            }
            if (param2.combo != null && param2.combo != "")
            {
                _loc_3 = getComboArr(param2);
                _loc_4 = 0;
                while (_loc_4 < _loc_3.length)
                {
                    
                    _loc_5 = SkillConfig.instance.getInfoById(_loc_3[_loc_4]);
                    if (_loc_5 != null)
                    {
                        if (_loc_5.series == param1.skillBelong)
                        {
                            return true;
                        }
                    }
                    _loc_4++;
                }
            }
            return false;
        }// end function

        private static function getComboArr(param1:TSkill) : Array
        {
            var _loc_2:* = comboDic[param1.skillId] as Array;
            if (_loc_2 != null)
            {
                return _loc_2;
            }
            _loc_2 = param1.combo.split("#");
            comboDic[param1.skillId] = _loc_2;
            return _loc_2;
        }// end function

        public static function getComboSkillByIndex(param1:TSkill, param2:int) : TSkill
        {
            if (param1 == null)
            {
                return null;
            }
            if (param1.combo == null)
            {
                return null;
            }
            if (param2 == 0)
            {
                return param1;
            }
            var _loc_3:* = getComboArr(param1);
            return SkillConfig.instance.getInfoById(_loc_3[(param2 - 1)]);
        }// end function

        public static function getComboSkillIndex(param1:TSkill, param2:int) : int
        {
            if (param1 == null || param1.combo == null)
            {
                return -1;
            }
            if (param1.skillId == param2)
            {
                return 0;
            }
            var _loc_3:* = getComboArr(param1);
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3.length)
            {
                
                if (_loc_3[_loc_4] == param2.toString())
                {
                    return (_loc_4 + 1);
                }
                _loc_4++;
            }
            return -1;
        }// end function

        public static function getCoolDownTime(param1:TSkill) : int
        {
            if (param1 == null)
            {
                return 0;
            }
            var _loc_2:* = Cache.instance.skill.getSkill(param1.skillId);
            if (_loc_2 != null)
            {
                return _loc_2.cooldownTime;
            }
            return param1.cooldownTime;
        }// end function

        public static function getCoolDownTimeStr(param1:TSkill, param2:Boolean = false) : String
        {
            if (param1 == null)
            {
                return "0";
            }
            var _loc_3:* = Cache.instance.skill.getSkill(param1.skillId);
            if (_loc_3 != null)
            {
                return _loc_3.getCoolDownSeconds(param2);
            }
            var _loc_4:* = param1.cooldownTime;
            if (_loc_4 % 1000 == 0)
            {
                return int(_loc_4 / 1000).toString();
            }
            return (_loc_4 / 1000).toFixed(1);
        }// end function

        public static function isToSelfSkill(param1:SkillInfo) : Boolean
        {
            if (param1.tSkill.type == ESkillType._ESKillTypeTornado || param1.tSkill.name == Language.getString(21099))
            {
                return false;
            }
            if ((param1.tSkill.targetType & ESkillTargetType._ESkillTargetTypeEnemy) > 0 && param1.tSkill.targetSelect == ESkillTargetSelect._ESkillTargetSelectSelf)
            {
                return true;
            }
            if ((param1.tSkill.targetType & ESkillTargetType._ESkillTargetTypeSelf) > 0)
            {
                return true;
            }
            if ((param1.tSkill.targetType & ESkillTargetType._ESkillTargetTypeMaster) > 0)
            {
                return true;
            }
            return false;
        }// end function

        public static function needSelectTarget(param1:int) : Boolean
        {
            var _loc_2:* = SkillConfig.instance.getInfoById(param1);
            return _loc_2 && _loc_2.targetSelect <= ESkillTargetSelect._ESkillTargetSelectNeedTarget && _loc_2.targetType != ESkillTargetType._ESkillTargetTypeSelf;
        }// end function

        public static function isDefenseCopyBeidongSkill(param1:int) : Boolean
        {
            var _loc_2:* = SkillConfig.instance.getInfoById(param1);
            if (_loc_2.triggerType == ESkillTriggType._ESkillTriggBeAttack || _loc_2.triggerType == ESkillTriggType._ESkillTriggBorn)
            {
                return true;
            }
            return false;
        }// end function

        public static function getSkillSeries(param1:int) : int
        {
            var _loc_2:int = 0;
            var _loc_3:* = SkillConfig.instance.getInfoById(param1);
            if (_loc_3)
            {
                _loc_2 = _loc_3.series > 0 ? (_loc_3.series) : (_loc_3.skillId);
            }
            return _loc_2;
        }// end function

        public static function canMapUseSkill(param1:SkillInfo, param2:FollowFightAIData) : Boolean
        {
            if (param2.target != null && param2.target is MonsterPlayer && BossRule.isCollectBoss(param2.target as MonsterPlayer))
            {
                return true;
            }
            if (GameMapUtil.isCanNotPlayerSkillMap())
            {
                return false;
            }
            return true;
        }// end function

        public static function isShouldGuideUseXPSkill() : Boolean
        {
            var _loc_1:* = new Rectangle(RolePlayer.instance.x2d - 400, RolePlayer.instance.y2d - 400, 800, 800);
            var _loc_2:* = ThingUtil.entityUtil.entitysMap.getEntityByRangle(_loc_1, EEntityType._EEntityTypeBoss);
            if (_loc_2 == null || _loc_2.length <= 4)
            {
                return false;
            }
            return true;
        }// end function

        public static function isPetSkill(param1:TSkill) : Boolean
        {
            return param1.career == ECareer._ECareerPhysPet;
        }// end function

        public static function isOtherSkill(param1:TSkill) : Boolean
        {
            var _loc_2:* = GameDefConfig.instance.getOtherSkillTypeByPosType(param1.posType);
            if (_loc_2 == ESkillCategory._EMountSkill || _loc_2 == ESkillCategory._EPetSkill || FashionUtil.isFashionSkill(_loc_2))
            {
                return true;
            }
            return false;
        }// end function

        public static function getLearnedSkillByType(param1:int) : Array
        {
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:Array = null;
            var _loc_7:SkillInfo = null;
            var _loc_2:Array = [];
            var _loc_3:* = GameDefConfig.instance.getOtherSkillPostTypeRect(param1);
            if (_loc_3.length > 0)
            {
                _loc_4 = _loc_3.shift();
                _loc_5 = _loc_3.shift();
                _loc_6 = Cache.instance.skill.getAllSkillsLearned();
                for each (_loc_7 in _loc_6)
                {
                    
                    if (_loc_7.tSkill.posType >= _loc_4 && _loc_7.tSkill.posType < _loc_5)
                    {
                        _loc_2.push(_loc_7);
                    }
                }
            }
            return _loc_2;
        }// end function

        public static function isNoSpasticitySkill(param1:SkillInfo) : Boolean
        {
            if (param1 == null)
            {
                return true;
            }
            if (param1.skillType == ESkillType._ESKillTypeTornado)
            {
                return true;
            }
            if (isNoStopAISkill(param1))
            {
                return true;
            }
            return false;
        }// end function

        public static function isNoStopAISkill(param1:SkillInfo) : Boolean
        {
            if (param1 == null)
            {
                return true;
            }
            if (param1.tSkill != null && (param1.tSkill.series == 10080 || param1.tSkill.series == 10100))
            {
                return true;
            }
            return false;
        }// end function

        public static function isBrillyGouriSkill(param1:int) : Boolean
        {
            return param1 == 51430761;
        }// end function

    }
}
